package cn.jobstart.task;

import cn.jobstart.common.StringUtil;
import cn.jobstart.modelExt.TalentSubscriptionTaskExt;
import cn.jobstart.pubInter.AbstractTask;
import cn.jobstart.service.ITalentSubscriptionTaskService;
import cn.jobstart.spider.service.ISpiderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author sunke
 * @version 1.0
 * @Description 人才订阅任务
 * @date 2023-10-07 15:30
 */

@EnableScheduling
@Slf4j
@Component
public class TalentTask extends AbstractTask {


    @Resource
    private ITalentSubscriptionTaskService talentSubscriptionTaskService;

    @Resource
    private ISpiderService spiderService;


    // @Scheduled(cron = "0 0 0/3 * * ?")
    @Override
    public void run() {

        try {

            TalentSubscriptionTaskExt talentSubscriptionTask = talentSubscriptionTaskService.getWaitRun();
            if (StringUtil.isNullOrEmpty(talentSubscriptionTask)) {
                return;
            }

            //说明有对象还在运行就不运行，后期改成那个对象在运行
            TalentSubscriptionTaskExt talentSubscriptionTaskRunning = talentSubscriptionTaskService.getRunning();
            if (StringUtil.isNotObjEmpty(talentSubscriptionTaskRunning)) {
                return;
            }

            spiderService.startTalentTaskByTalentSubscriptionTask(talentSubscriptionTask);

        } catch (Exception e) {

        }


    }
}
